package co.fitstart.entity.course.round;

import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;

import co.fitstart.entity.course.CourseType;
import co.fitstart.entity.order.Order;

/**
 * 
 * @author lidan
 *
 */
public class OnlineRoundAttr {
    
    /** 学员BMI */
    private BigDecimal bmiValue;
    
    /** ZIP文件名 */
    private String zipName;
    
    /** 是否上传二维码 */
    private boolean qrcodeStatus;
    
    /** 是否老学员 */
    private boolean oldStudent;
    
    /** 分组状态 */
    private OnlineRoundGroupStatus onlineRoundGroupStatus;
    
    /**
     * The default constructor
     */
    public OnlineRoundAttr() {
        
    }
    
    /**
     * 
     * @param courseType
     * @return
     */
    public OnlineRoundAttr initilization(CourseType courseType, int onlineCount) {
        this.qrcodeStatus = false;
        this.oldStudent = onlineCount > 1;
        if (courseType.isOnline()) {
            this.onlineRoundGroupStatus = OnlineRoundGroupStatus.DISALLOW_GROUP;
        }
        return this;
    }
    
    /**
     * 
     * @param bmiValue
     * @param zipName
     * @param qrcodeStatus
     * @param onlineRoundGroupStatus
     * @return
     */
    public OnlineRoundAttr generate(BigDecimal bmiValue, String zipName, boolean qrcodeStatus, OnlineRoundGroupStatus onlineRoundGroupStatus) {
        this.bmiValue = bmiValue;
        this.zipName = zipName;
        this.qrcodeStatus = qrcodeStatus;
        this.onlineRoundGroupStatus = onlineRoundGroupStatus;
        return this;
    }
    
    /**
     * 
     * @param order
     * @return
     */
    public OnlineRoundAttr editZipName(Order order) {
        String filename = org.apache.commons.lang3.StringUtils.replace(order.getProduct().getName(), " ", "-");
        String[] strings = StringUtils.split(zipName, "_");
        String name = "[" + order.getOrderStatus().getDescription() + "-" + order.getPaymentStatus().getDescription() + "]" + filename;
        
        for(int i = 1; i<strings.length; i++) {
            name = name + "_" + strings[i];
        }
        this.zipName = name;
        return this;
    }
    
    /**
     * 
     * @param wechatNumber
     * @return
     */
    public OnlineRoundAttr editZipName(String wechatNumber) {
        String[] zipNames = StringUtils.split(zipName, "_");
        
        String name = "";
        for(int i = 0; i<zipNames.length; i++) {
            if (i == 0) {
                name = name + zipNames[i];
            } else if(i == 2) {
                name = name + "_" + wechatNumber;
            } else {
                name = name + "_" + zipNames[i];
            }
        }
        this.zipName = name;
        return this;
    }
    
    /**
     * 
     * @param onlineRoundGroupStatus
     * @return
     */
    public OnlineRoundAttr editGroupStatus(OnlineRoundGroupStatus onlineRoundGroupStatus) {
        this.onlineRoundGroupStatus = onlineRoundGroupStatus;
        return this;
    }

    /**
     * @return the bmiValue
     */
    public BigDecimal getBmiValue() {
        return bmiValue;
    }

    /**
     * @return the zipName
     */
    public String getZipName() {
        return zipName;
    }

    /**
     * @return the qrcodeStatus
     */
    public boolean isQrcodeStatus() {
        return qrcodeStatus;
    }

    /**
     * @return the oldStudent
     */
    public boolean isOldStudent() {
        return oldStudent;
    }

    /**
     * @return the onlineRoundGroupStatus
     */
    public OnlineRoundGroupStatus getOnlineRoundGroupStatus() {
        return onlineRoundGroupStatus;
    }

    /**
     * @param bmiValue the bmiValue to set
     */
    public void setBmiValue(BigDecimal bmiValue) {
        this.bmiValue = bmiValue;
    }

    /**
     * @param zipName the zipName to set
     */
    public void setZipName(String zipName) {
        this.zipName = zipName;
    }

    /**
     * @param qrcodeStatus the qrcodeStatus to set
     */
    public void setQrcodeStatus(boolean qrcodeStatus) {
        this.qrcodeStatus = qrcodeStatus;
    }

    /**
     * @param oldStudent the oldStudent to set
     */
    public void setOldStudent(boolean oldStudent) {
        this.oldStudent = oldStudent;
    }

    /**
     * @param onlineRoundGroupStatus the onlineRoundGroupStatus to set
     */
    public void setOnlineRoundGroupStatus(OnlineRoundGroupStatus onlineRoundGroupStatus) {
        this.onlineRoundGroupStatus = onlineRoundGroupStatus;
    }
    
    

}
